#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include "SuffixArray.h"
using namespace std;


void read_text(string& text, string fileName) {
	ifstream file(fileName.c_str());
	if (file.is_open()) {
		string line;
		while (file.good()) {
			getline(file, line);
					text.append(line);
					text.append("\n");
                }
                file.close();
        }
}

int main() {

	string text;
	vector<int> suf;
	vector<int> indexes;
	read_text(text, "input.txt");

	SuffixArray sa;
	sa.Build(text);
	//cout<<"======="<<endl;
	bool work=true;
	string word;
	while (work) {
		getline(cin, word);
		if (word.empty()) {
			break;
		}
		sa.binSearch(word, indexes, 0, text.size()-1);
		if (indexes.empty()) {
			cout<<"No matches"<<endl;
		} else {
			cout<<"Matches: ";
			for (int i=0; i<indexes.size(); i++) {
				cout<<indexes[i]<<" ";
			}
			cout<<endl;
		}
		indexes.clear();
	}

	system("pause");
	return 0;
}